import {LoginPage} from "../../pages/login/login";
import {SLLocalStorageUtils} from "./SLLocalStorageUtils";
import {Log} from "./Log";
import {WebUrl} from "../interface/webUrl";
export class Utils {
    private static TAG: string = 'Utils';
    static server: { ip?: string, port?: string } = {
        ip: WebUrl.ip,
        port: WebUrl.port
    };

    static isAssetTypeAnImage(ext) {

        return [
            'png', 'jpg', 'jpeg', 'bmp', 'gif', 'webp', 'psd', 'svg', 'tiff'].indexOf(ext.toLowerCase()) !== -1;

    }

    static isNullOrUndefined(obj) {
        return typeof obj == "undefined" || obj == null;
    }

    static async getPort() {
        try {
            this.server.ip = Utils.isNullOrUndefined(await SLLocalStorageUtils.getInstance().get_Ip())
                ? WebUrl.ip : await SLLocalStorageUtils.getInstance().get_Ip();
            this.server.port = Utils.isNullOrUndefined(await SLLocalStorageUtils.getInstance().get_Port())
                ? WebUrl.port : await SLLocalStorageUtils.getInstance().get_Port();
            Log.d(Utils.TAG, "this.server.ip == " + this.server.ip);
            Log.d(Utils.TAG, "this.server.port== " + this.server.port);

            this.settingPort(this.server.ip, this.server.port)
        } catch (error) {
            Log.printObj(Utils.TAG, "error == ", error);
        }
    }

    static async settingPort(ip, port) {
        WebUrl.setIpAndPost(ip, port);
        WebUrl.baseUrl = 'http://' + ip + ':' + port;
        WebUrl.baseSetting(WebUrl.baseUrl);
        try {
            await SLLocalStorageUtils.getInstance().saveUrl(ip, port);
            // this.getBaseUrl();

        } catch (error) {
            Log.printObj(Utils.TAG, "error == ", error);
            throw error;
        }
    }
}
